import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = () => import('@/components/Login.vue')
const Home = () => import('@/components/Home.vue')
const Qx = () => import('@/views/qxmanage')
const Usermanage = () => import('@/views/usermanage')

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component:Login
  },
  {
    path: '/',
    redirect: '/login'
  },
  {
    path:'/home',
    component:Home,
    children:[
      {path:'usermanage',component:Usermanage},
      {path:'qx',component:Qx}
    ]
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if(to.path === '/login'){return next()}
  const tokenstr = window.sessionStorage.getItem('token')//取出token判断是否放行
  if(!tokenstr){
    next('/login')
  }else{
    next();
  }
})

export default router
